package com.g.ocache.impl.store.entry;

import java.lang.ref.SoftReference;

import com.g.ocache.StoreEntry;



/**
 * 
 * @author Jingqi Xu
 */
public final class SoftStoreEntry<K, V> implements StoreEntry<K, V> {
	//
	private final K key;
	private final SoftReference<V> value;

	/**
	 * 
	 */
	public SoftStoreEntry(K key, V value) {
		this.key = key;
		this.value = new SoftReference<V>(value);
	}

	/**
	 * 
	 */
	public K getKey() {
		return key;
	}

	public V getValue() {
		return value.get();
	}

	public boolean isExpired() {
		return value.get() == null;
	}
	
	/**
	 * 
	 */
	public static class FactoryImpl<K, V> implements Factory<K, V> {
		
		public StoreEntry<K, V> create(K key, V value) {
			return new SoftStoreEntry<K, V>(key, value);
		}
	}
}
